package com.qc.sys.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qc.sys.entity.SysRole;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.List;

/**
 * (SysRole)表数据库访问层
 *
 * @author AltmanQccc
 * @since 2020-09-02 10:55:32
 */
@Repository
public interface SysRoleDao extends BaseMapper<SysRole> {

    @Delete("delete from sys_role_menu where rid = #{id}")
    void deleteRoleMenuByRid(Serializable id);

    @Delete("delete from sys_role_menu where mid = #{id}")
    void deleteRoleMenuByMid(Serializable id);

    @Delete("delete from sys_role_user where rid = #{id}")
    void deleteRoleUserByRid(Serializable id);

    @Delete("delete from sys_role_user where uid = #{id}")
    void deleteRoleUserByUid(Serializable id);

    @Select("select mid from sys_role_menu where rid = #{id}")
    List<Integer> queryMenuIdsByRid(Integer id);

    @Insert("insert into sys_role_menu(rid,mid) values(#{rid},#{mid})")
    void insertRoleMenu(Integer rid, Integer mid);

    @Select("select rid from sys_role_user where uid = #{userId}")
    List<Integer> queryRoleIdsByRid(Integer userId);

    List<Integer> queryMenuIdsByRids(@Param("roleIds") List<Integer> roleIds);

    @Select("select rid from sys_role_user where uid=#{id}")
    List<Integer> queryRoleIdsByUserId(Integer id);
}